package com.example.web.controller;

import com.example.web.event.PriceEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@Slf4j
public class EventController {


    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping("/event")
    public ResponseEntity event() {
        PriceEvent priceEvent = new PriceEvent(this,1L,BigDecimal.valueOf(10),BigDecimal.valueOf(11));
        applicationContext.publishEvent(priceEvent);
        return ResponseEntity.ok().build();
    }

}
